<template>
  <div class="add" :class="[callScreen?'call-screen-add':'',callBackAdd?'show-callback-add':'']">
    <el-form v-if="hasFetchData" :model="form" :class="{'is-merge': isMergeCustomer}" :validateOnRuleChange="false" :rules="rules" ref="form" label-position="top">
      <el-row :gutter="20">
        <el-col :span="isFull?24:12">
          <el-form-item :label="showItem.name" :prop="noUpdate.name ? null : 'name'">
            <el-input size="mini" v-model.trim="form.name" :disabled="noUpdate.name"></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="isFull?24:12" :key="'custStatus'">
          <el-form-item :label="$t('customer.custStatus')" prop="status">
            <customer-status-select ref="custStatus" :isFull="isFull" :placeholder="$t('public.pleasePick')" :status="custInfo ? custInfo.status : null" @statusChange="handleStatusChange">
            </customer-status-select>
          </el-form-item>
        </el-col>
        <el-col :span="isFull?24:24" v-show="showItem.title && !isShowItem.title">
          <el-form-item :label="showItem.title" :prop="!noUpdate.title && !isShowItem.title?'title':null">
            <el-input size="mini" type="textarea" v-model="form.title" :disabled="noUpdate.title"></el-input>
          </el-form-item>
        </el-col>
      </el-row>

      <!-- // 电话 start-->
      <el-row :gutter="20">
        <template>
          <el-col :span="isFull?24:8">
            <el-form-item :label="showItem.phone"  prop="phone">
              <el-input size="mini" :disabled="noUpdate['phone']" v-model.trim="phone[0].tel"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="isFull?24:15">
            <el-form-item :label="isFull?'':showItem.phoneMemo">
              <el-input size="mini" :disabled="noUpdate['phone']" :placeholder="isFull?showItem.phoneMemo:''" v-model.trim="phone[0].memo"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="isFull?24:1" v-show="!noUpdate['phone']" :class="{'full-add': isFull}" style="padding-left: 3px">
            <span class="push" @click.stop="addLink('phone')"><i class="el-icon-plus"></i></span>
          </el-col>
        </template>
      </el-row>

      <el-row class="add-item" v-for="(phon,index) in phone" v-if="index !== 0" :gutter="20">
        <el-col :span="isFull?24:8">
          <el-form-item v-if="isFull" :label="showItem.phone">
            <el-input size="mini" :disabled="noUpdate['phone']" v-model.trim="phon.tel"></el-input>
          </el-form-item>
          <el-input size="mini" v-else :disabled="noUpdate['phone']" v-model.trim="phon.tel"></el-input>
        </el-col>
        <el-col :span="isFull?24:15">
          <el-input size="mini" :disabled="noUpdate['phone']" :placeholder="isFull?showItem.phoneMemo:''" v-model.trim="phon.memo"></el-input>
        </el-col>
        <el-col :span="isFull?24:1" :class="{'full-del': isFull}" v-show="!noUpdate['phone']" style="padding-left: 3px">
          <span class="push del" @click.stop="delLink('phone',index)"><i class="el-icon-minus"></i></span>
        </el-col>
      </el-row>
      <!-- // 电话号码字段 end-->

      <!-- // 邮箱字段 start-->
      <el-row :gutter="20" v-if="!isShowItem.email">
        <template v-if="showItem.email">
          <el-col :span="isFull?24:8" >
            <el-form-item :label="showItem.email" prop="email">
              <el-input size="mini" v-model.trim="email[0].email"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="isFull?24:15">
            <el-form-item :label="isFull?'':showItem.emailMemo">
              <el-input size="mini" :placeholder="isFull?showItem.emailMemo:''" v-model.trim="email[0].memo"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="isFull?24:1" style="padding-left: 3px" :class="{'full-add': isFull}">
            <span class="push" @click.stop="addLink('email')"><i class="el-icon-plus"></i></span>
          </el-col>
        </template>
      </el-row>
      <el-row class="add-item" v-for="(emai,index) in email" v-if="index !== 0 && !isShowItem.email" :gutter="20">
        <el-col :span="isFull?24:8">
          <el-form-item v-if="isFull" :label="showItem.email">
            <el-input size="mini" v-model.trim = "emai.email"></el-input>
          </el-form-item>
          <el-input size="mini" v-else v-model.trim = "emai.email"></el-input>
        </el-col>
        <el-col :span="isFull?24:15">
          <el-input :placeholder="isFull?showItem.emailMemo:''" size="mini" v-model.trim = "emai.memo"></el-input>
        </el-col>
        <el-col :span="isFull?24:1" style="padding-left: 3px" :class="{'full-del': isFull}">
          <span class="push del" @click.stop="delLink('email',index)"><i class="el-icon-minus"></i></span>
        </el-col>
      </el-row>
      <!-- // 邮箱字段 end-->
      <!-- // 微信字段 start-->
      <el-row :gutter="20" v-if="!isShowItem.weixin">
        <template v-if="showItem.weixin">
          <el-col :span="isFull?24:8">
            <el-form-item :label="showItem.weixin" prop="weixin">
              <el-input size="mini" v-model.trim="weixin[0].num"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="isFull?24:15">
            <el-form-item :label="isFull?'':showItem.weixinMemo">
              <el-input size="mini" :placeholder="isFull?showItem.weixinMemo:''" v-model.trim="weixin[0].memo"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="isFull?24:1" style="padding-left: 3px" :class="{'full-add': isFull}">
              <span class="push" @click.stop="addLink('weixin')"><i class="el-icon-plus"></i></span>
          </el-col>
        </template>
      </el-row>
      <el-row class="add-item" v-for="(item,index) in weixin" v-if="index !== 0 && !isShowItem.weixin" :gutter="20">
          <el-col :span="isFull?24:8">
            <el-form-item v-if="isFull" :label="showItem.weixin">
              <el-input size="mini" v-model.trim = "item.num"></el-input>
            </el-form-item>
              <el-input v-else size="mini" v-model.trim = "item.num"></el-input>
          </el-col>
          <el-col :span="isFull?24:15">
              <el-input size="mini" :placeholder="isFull?showItem.weixinMemo:''" v-model.trim = "item.memo"></el-input>
          </el-col>
          <el-col :span="isFull?24:1" style="padding-left: 3px" :class="{'full-del': isFull}">
            <span class="push del" @click.stop="delLink('weixin', index)" ><i class="el-icon-minus"></i></span>
          </el-col>
      </el-row>
      <!-- // 微信字段 end-->
      <el-row :gutter="20" :key="'provinceCity'">
        <el-col :span="isFull?24:16" :key="'cusProvinceCity'" class="cus-province" :class="rules.province ? '' : 'star-show'" v-show="!isShowItem.province">
          <span class="star" v-if="rules.province">*</span>
          <el-form-item :label="$t('public.provinceCity')" :prop="!noUpdate.province && !isShowItem.province?'province':null">
            <area-linkage
              ref="areaLink"
              :loyout="isFull?'full':'inline'"
              :disabled="noUpdate.province"
              :provinceName="'province'"
              :provinceValue="province"
              :districtValue="district"
              :cityName="'city'"
              :cityValue="city"
              @valueChange="handleAreaLinkageChange"
            ></area-linkage>
          </el-form-item>
        </el-col>

        <el-col :span="isFull?24:8" v-show="showItem.address && !isShowItem.address">
          <el-form-item :label="showItem.address" :prop="!noUpdate.address && !isShowItem.address?'address':null">
            <el-input size="mini" v-model.trim="form.address" :disabled="noUpdate.address"></el-input>
          </el-form-item>
        </el-col>

        <el-col :span="isFull?24:24" v-show="showItem.note && !isShowItem.note">
          <el-form-item :label="showItem.note" :prop="!noUpdate.note && !isShowItem.note?'note':null">
            <el-input size="mini" type="textarea" v-model="form.note" :disabled="noUpdate.note"></el-input>
          </el-form-item>
        </el-col>

        <el-col :span="isFull?24:12" v-show="templateType!=='personal' && showItem.web && !isShowItem.web">
          <el-form-item :label="showItem.web" :prop="!noUpdate.web && !isShowItem.web?'web':null">
            <el-input size="mini" v-model.trim="form.web" :disabled="noUpdate.web"></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="isFull?24:8" v-show="templateType==='personal' && showItem.sex && !isShowItem.sex">
          <el-form-item :label="showItem.sex" :prop="!noUpdate.sex && !isShowItem.sex?'sex':null">
            <el-radio-group v-model.trim="form.sex" >

              <el-radio class="radio"  label="0">{{$t('public.male')}}</el-radio>
              <el-radio class="radio" label="1">{{$t('public.famel')}}</el-radio>
            </el-radio-group>
          </el-form-item>
        </el-col>

        <el-col :span="isFull?24:10" v-show="templateType==='personal' && showItem.birth && !isShowItem.birth">
          <el-form-item :label="showItem.birth" :prop="!noUpdate.birth && !isShowItem.birth?'birth':null">
            <el-date-picker
              :id="'perBirthDate'"
              :disabled="noUpdate.birth"
              v-model="form.birth"
              type="date"
              :placeholder="$t('business.chooseDate')">
            </el-date-picker>
          </el-form-item>
        </el-col>

        <el-col :span="isFull?24:6" v-show="templateType==='personal' && showItem.age && !isShowItem.age">
          <el-form-item :label="showItem.age" :prop="!noUpdate.age && !isShowItem.age?'age':null">
            <el-input size="mini" v-model.trim="form.age" :disabled="noUpdate.age"></el-input>
          </el-form-item>
        </el-col>

        <el-col :span="isFull?24:12" v-if="templateType!=='personal'" :key="'dataSource'">
          <el-form-item :label="$t('customer.dataSource')">
            <customer-source-select :isFull="isFull" :placeholder="$t('public.pleasePick')" :source="custInfo ? custInfo.custsource1 : null" @sourceChange="handleSourceChange">
            </customer-source-select>
          </el-form-item>
        </el-col>

        <el-col :span="isFull?24:12" :key="'customerOwner'">
          <el-form-item :label="$t('customer.customerOwner')">
            <customer-owner-select ref="owner" :rangeType="rangeType" :isFull="isFull" :placeholder="$t('public.pleasePick')" :categoryId="custInfo? custInfo.categoryId: null" :owner="custInfo ? custInfo.owner: null" @ownerChange="handleOwnerChange">
            </customer-owner-select>
          </el-form-item>
        </el-col>
        <el-col :span="isFull?24:12" v-show="showItem.thirdPartyRelationId && !isShowItem.thirdPartyRelationId">
          <el-form-item :label="showItem.thirdPartyRelationId" :prop="!noUpdate.thirdPartyRelationId && !isShowItem.thirdPartyRelationId?'thirdPartyRelationId':null">
            <el-input size="mini" v-model.trim="form.thirdPartyRelationId" :disabled="noUpdate.thirdPartyRelationId"></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="isFull?24:24">
          <el-form-item :label="$t('public.attach')">
            <template v-if="Object.keys(this.files).length">
              <p v-for="(item, index) in this.files" :key="index">
                {{ `${item.file.name}上传进度：` }}<el-progress :percentage="item.percent" ></el-progress>
              </p>
            </template>
            <el-upload
              ref="upload"
              multiple
              :action="uploadUrl"
              :data="uploadData"
              :on-preview="handlePreview"
              :before-remove="beforeRemove"
              :on-success="isUseQiniu ?handleSuccess : () => {}"
              :before-upload="isUseQiniu ? beforeUpload : cosBeforeUpload"
              v-bind="{...(isUseQiniu ? {} : {'http-request': onUpload})}"
              :file-list="attachs">
              <el-button size="mini" type="primary" class="btn-color">{{$t('public.clickUpload')}}</el-button>
              <div class="el-upload__tip" slot="tip">{{$t('public.uploadSizeDes')}}</div>
            </el-upload>
          </el-form-item>
        </el-col>

      </el-row>
        <!-- 客户固定字段 end -->
      <legend v-if="optionsCustomFields.length>0" style="width: 475px;margin-bottom: 12px;font-size:14px;">{{$t('customer.customField')}}</legend>
        <!-- 自定义字段 start -->
      <el-row :gutter="20">
        <div v-for="(item, index) in optionsCustomFields">
          <el-col class="height-68" :span="isFull?24:8"  v-if="(item.inputType==='input' || item.inputType==='date' || item.inputType==='datetime') && item.status !== 'stop'">
            <el-form-item
            :label="item.label"
            :prop="noUpdate[item.name] ? null : item.name">
              <el-input size="mini" v-if="item.inputType==='input' && item.validateType !== 'Number'" v-model.trim="form[item.name]" :disabled="noUpdate[item.name]"></el-input>
              <el-input size="mini" v-if="item.inputType==='input' && item.validateType === 'Number'" v-model.trim="form[item.name]" :disabled="noUpdate[item.name]"></el-input>
              <el-date-picker
                v-if="item.inputType==='date'"
                size="mini"
                :id="item.name + index"
                v-model.trim="form[item.name]"
                type="date"
                :placeholder="$t('public.pleasePick')"
                align="right"
                :editable="isEditable"
                :picker-options="pickerOptions1"
                :disabled="noUpdate[item.name]">
              </el-date-picker>
              <el-date-picker
                v-if="item.inputType==='datetime'"
                size="mini"
                :id="item.name + index"
                v-model.trim="form[item.name]"
                type="datetime"
                :placeholder="$t('public.pleasePick')"
                align="right"
                :editable="isEditable"
                :picker-options="pickerOptions2"
                :disabled="noUpdate[item.name]">
              </el-date-picker>
            </el-form-item>
          </el-col>

          <el-col class="height-68" :span="isFull?24:8"  v-if="item.inputType==='select' && item.status !== 'stop'">
            <el-form-item
            :label="item.label"
            :prop="noUpdate[item.name] ? null : item.name">
              <el-select
              :value-key="form[item.name]"
              size="mini"
              v-if="item.inputType==='select'"
              v-model.trim="form[item.name]"
              :placeholder="$t('public.pleasePick')"
              :disabled="noUpdate[item.name]">
                <el-option
                  v-for="item2 in item.data"
                  :key="item2.value"
                  :label="item2.label"
                  :value="item2.value">
                </el-option>
              </el-select>
            </el-form-item>
          </el-col>

          <el-col class="height-68" :span="isFull?24:8"  v-if="item.inputType==='cascade' && item.status !== 'stop'">
            <el-form-item
            :label="item.label"
            :prop="noUpdate[item.name] ? null : item.name">
              <cascader
                ref="cascader"
              v-if="item.data && item.data.isDic"
              :skipInitValidate=true
              :isFull="isFull"
              :disabled="noUpdate[item.name]"
              :optionsId="item.data.dicId"
              :initCascaderValue="form[item.name]"
              :formId="item.name"
              @change="handleCascader">
              </cascader>
            </el-form-item>
          </el-col>

          <el-col class="" :span="isFull?24:24"  v-if="(item.inputType==='textarea' || item.inputType==='checkbox' || item.inputType==='radio') && item.status !== 'stop'">
            <el-form-item
            :label="item.label"
            :prop="noUpdate[item.name] ? null : item.name">
              <el-input size="mini"
              type="textarea"
              v-if="item.inputType==='textarea'"
              v-model="form[item.name]"
              :disabled="noUpdate[item.name]">
              </el-input>

              <el-checkbox-group  v-if="item.inputType==='checkbox'" :value="Array.isArray(form[item.name]) ? form[item.name] : []" @input="form[item.name]=$event">
                <el-checkbox
                  v-for="item2 in item.data"
                  :key="item2.value"
                  :label="item2.value"
                  :disabled="noUpdate[item.name]">
                  {{item2.label}}
                </el-checkbox>
              </el-checkbox-group>

              <div v-if="item.inputType==='radio'">
                <el-radio-group  v-model.trim="form[item.name]">
                  <el-radio
                    size="mini"
                    :key="item2.value"
                    v-for="item2 in item.data"
                    :label="item2.value"
                    :disabled="noUpdate[item.name]">
                    {{item2.label}}
                  </el-radio>
                </el-radio-group>
              </div>

            </el-form-item>
          </el-col>
        </div>
      </el-row>
      <!-- 自定义字段 end -->
      <el-form-item class="form__footer">
        <el-popover
            ref="popover1"
            placement="bottom"
            width="80"
            trigger="hover">
            <ul class="dropdownStyle">
                <li v-for="(item,index) of joinBlackType" :key='index' @click="addCdrBlackList(tel,item.type,item.label)">{{item.label}}</li>
            </ul>
        </el-popover>
        <el-button  class="primary_btn" v-if="isBlight && isToBlackList" v-popover:popover1>{{$t('webchat.addBlack')}}</el-button>
        <el-button type="primary" class="primary_btn" @click.stop="submit">{{$t('public.save')}}</el-button>
        <el-button  class="primary_btn" @click.stop="callBackAddCust" v-if="callBackAdd">{{$t('public.getback')}}</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>
<script type="text/javascript">
  import AreaLinkage from '@/components/ui-modules/area-linkage/newAreaLinkage.vue'
  import CustomerStatusSelect from './CustomerStatusSelect.vue'
  import CustomerSourceSelect from './CustomerSourceSelect.vue'
  import CustomerOwnerSelect from './CustomerOwnerSelect.vue'
  import Cascader from '@/components/public-modules/cache/CascaderCust.vue'
  import bus from '@/store/eventBus'
  import { deepClone, getCurrentDate, checkHideTel, isHasFunc, phoneFilterChats, UPLOAD_LIMITED_TYPE } from '@/utils/m7Utils'
  import {formRollToFirstError} from '@/utils/validate'
  import { notUpdateCustomerField, isHideTel, getCityValue } from '@/utils/customerUtils.js'
  import * as uuid from 'uuid'
  import { uploadQRcode } from '@/utils/qiniuUtils'
  import { qiniuUploadUrl, qiniu7moorDomain } from '@/utils/qiniuUtils'
  import { common } from '@/utils/cosUrl'
  import {checkform} from '@/utils/validate.js'
  import * as globalTypes from '@/store/mutation-types.js'
  let isLeafObj = {}
  export default{
    name: 'AddCus',
    props: {
      rangeType: String, // 无归属判定 观察中
      pickerName: String,
      // 是否是在线咨询，在线咨询占满24
      isFull: false,
      editCustType: {
        type: String,
        default: 'add'
      },
      // 当前用户信息
      custInfo: {
        type: Object,
        default: function () {
          return {}
        }
      },
      // 当前是哪个模块
      currentBusinessObj: {
        type: Object,
        default: function () {
          return {}
        }
      },
      isBlight: {
        type: Boolean,
        default: false
      },
      tel: String,
      // 客户合并模块的时候展示合并预览样式调整控制
      isMergeCustomer: Boolean,
      callScreen: Boolean,
      callBackAdd: Boolean
    },
    data () {
      return {
        pickerOptions1: {
          shortcuts: [{
            text: this.$t('customer.today'),
            onClick (picker) {
              picker.$emit('pick', new Date())
            }
          }, {
            text: this.$t('customer.yesterday'),
            onClick (picker) {
              const date = new Date()
              date.setTime(date.getTime() - 3600 * 1000 * 24)
              picker.$emit('pick', date)
            }
          }]
        },
        pickerOptions2: {
          shortcuts: [{
            text: this.$t('customer.today'),
            onClick (picker) {
              picker.$emit('pick', new Date())
            }
          }, {
            text: this.$t('customer.yesterday'),
            onClick (picker) {
              const date = new Date()
              date.setTime(date.getTime() - 3600 * 1000 * 24)
              picker.$emit('pick', date)
            }
          }]
        },
        district: '',
        radio: 1,
        provinceCache: null,
        cityOptions: [],
        oldDic: [], // 兼容老字典
        uploadUrl: qiniuUploadUrl,
        uploadData: {},
        templateType: '',
        isEditable: false,
        // 格式化时间数组，让其通过校验
        dateIdArr: [],
        attachs: [],
        isShowItem: {},
        showItem: {
          name: ''
        },
        form: {},
        rules: {
          status: [
            { required: true, message: this.$t('public.pleaseInput') + this.$t('customer.custStatus'), trigger: 'change' }
          ]
        },
        noUpdate: { phone: false, name: false, title: false, province: false, address: false, note: false, web: false },
        optionsCustomFields: [],
        value: '',
        phone: [{ memo: '', tel: '' }],
        email: [{ memo: '', email: '' }],
        weixin: [{ memo: '', num: '' }],
        isToBlackList: false,
        hasFetchData: false,
        isUseQiniu: this.$store.state.isUseQiniu,
        files: {},
        joinBlackType:[
          {
            label:'仅呼入',
            type: '1'
          },
          {
            label:'仅外呼',
            type: '2'
          },
          {
            label:'呼入和外呼',
            type: '3'
          },
        ]
      }
    },
    computed: {
      cmpDomain () {
        return this.isUseQiniu ? '' : this.$store.state.fileDomain.cos7moorCommonDomain
      },
      // 是否隐藏手机号
      isHideTel () {
        return isHideTel(this.$store.state.session.user)
      },
      // 处理省的回显
      province () {
        if (this.custInfo && this.custInfo.callProvince) {
          for (let i in this.provinceCache) {
            if (this.provinceCache[i].name === this.custInfo.callProvince) {
              this.cityOptions = this.provinceCache[i].options
              this.form.province = this.provinceCache[i].key // 解决来电新增客户省市没有change拿不到值的问题
              return this.provinceCache[i].key
            }
          }
        } else if (this.custInfo && this.custInfo.fields) {
          for (let i = 0; i < this.custInfo.fields.length; i++) {
            let field = this.custInfo.fields[i]
            if (field.k === 'province') {
              return field.v
            }
          }
        }
        if (this.$refs.areaLink) {
          this.$refs.areaLink.resetProv()
        }
        return null
      },
      // 处理市的回显
      city () {
        if (this.cityOptions && this.cityOptions.length > 0 && this.custInfo.callCity) {
          for (let i in this.cityOptions) {
            if (this.cityOptions[i].name === this.custInfo.callCity) {
              this.form.city = this.cityOptions[i].key // 解决来电新增客户省市没有change拿不到值的问题
              return this.cityOptions[i].key
            }
          }
        } else if (this.custInfo && this.custInfo.fields) {
          for (let i = 0; i < this.custInfo.fields.length; i++) {
            let field = this.custInfo.fields[i]
            if (field.k === 'city') {
              let city = ''
              // 获取市区 县的值 如果有老数据 则比对出相对应的新数据
              let ctiyOrDistrict = getCityValue(this.oldDic, field.v)
              if (!ctiyOrDistrict) {
                city = field.v
                this.district = this.custInfo && this.custInfo.district ? this.custInfo.district : null
              } else {
                city = ctiyOrDistrict.city
                this.district = ctiyOrDistrict.district || ''
              }
              return city
            }
          }
        }
        this.district = null
        return null
      }
    },
    components: {
      AreaLinkage,
      CustomerOwnerSelect,
      CustomerSourceSelect,
      CustomerStatusSelect,
      Cascader
    },
    methods: {
      onProgress ({total, file}) {
        const percent = total.percent
        // this.$refs.upload.onProgress({percent})
        this.$set(this.files, file.name, {
          file,
          percent
        })
      },
      async onUpload (info) {
        const { file } = info
        if (file.size > 50 * 1024 * 1024) {
          this.$message.error(this.$t('customer.attachSizeOverLimit'))
          return false
        }
        uploadQRcode(file, file.name, this.onProgress, this.handleSuccess, file.key, null, this.cmpDomain)
        return true
      },
      // 处理日期时间
      getFormatDateTime (date) {
        date = new Date(date) // 解决个人版的生日是字符串直接getFullYear的操作，导入和或者是手动添加的客户，编辑的时候都有问题
        let year = date.getFullYear()
        let month = date.getMonth()
        let day = date.getDate()
        let hour = date.getHours()
        let minites = date.getMinutes()
        month = month + 1 > 9 ? month + 1 : '0' + (month + 1)
        day = day > 9 ? day : '0' + day
        hour = hour > 9 ? hour : '0' + hour
        minites = minites > 9 ? minites : '0' + minites
        return year + '-' + month + '-' + day + ' ' + hour + ':' + minites
      },
      // 隐藏手机号
      hideTel (tel) {
        return checkHideTel(tel, this.$store.state.session.user)
      },
      /**
       * 通话模块加入黑名单
       * @param {[type]} phoneNum [description]
       */
      addCdrBlackList (phoneNum,type,label) {
        if (/\D/g.test(phoneNum)) {
          this.$message.error(this.$t('call.phoneNumNoRight'))
          return false
        }
        // 呼入和外呼去掉仅字提示
        let newLabel = ''
        if(type == '1' || type == '2') {
          newLabel = label.substring(1,3)
        } else {
          newLabel = label
        }
        this.blackListConfirm(phoneNum,type,newLabel)
      },
      blackListConfirm(phoneNum,phoneType,label){
        this.$confirm(this.$t('call.blackListConfirmType',{type: label}), this.$t('public.tip'), {
          confirmButtonText: this.$t('public.confirm'),
          cancelButtonText: this.$t('public.cancel'),
          cancelButtonClass: 'primary_btn',
          confirmButtonClass: 'primary_btn',
          type: 'warning'
        }).then(() => {
          let data = {}
           let user = this.$store.state.session.user
          data.PBX = user.pbx
          data.Account = user.account
          data.BlackNum = phoneNum
          let displayName = user.displayName
          let exten = user.exten
          data.Memo = this.$t('customer.memo', {displayName, exten})
          let routeArry = this.$route.path.split('/')
          let tabType = routeArry[3]
          let lastData = {}
          // 当时加入呼入与外呼时掉两次接口
          if(phoneType == '3') {
            let newData = deepClone(data)
            newData.Type = '1'
            newData.phoneType = '3'
            lastData = {data: newData, type: tabType}
            this.$store.dispatch('saveBlackList', lastData)
            let data1 = deepClone(data)
            data1.Type = '2'
            data1.phoneType = '3'
            let lastData1 = {data: data1, type: tabType}
            this.$store.dispatch('saveBlackList', lastData1)
          } else {
            data.Type = phoneType
            data.phoneType = phoneType
            lastData = {data: data, type: tabType}
            this.$store.dispatch('saveBlackList', lastData)
          }
        }).catch(() => {
          console.log('取消')
        })
      },
      handleAttachs () {
        let imgTypes = ['jpg', 'jpeg', 'gif', 'png', 'bmp']
        this.initFileMap()
        let _attchsArr = this.$refs.upload.uploadFiles.map(
          i => (this.fileMap[i.uid] && !i.isNew) ? ({ ...i, id: this.fileMap[i.uid]}) : i
        )
        let _list = []
        for (let i = 0; i < _attchsArr.length; i++) {
          if (_attchsArr[i].id) {
            _list.push(_attchsArr[i])
          } else if (_attchsArr[i].status === 'success') {
            let _obj = {
              id: _attchsArr[i].id,
              isNew: 1,
              name: _attchsArr[i].name,
              status: 'success',
              type: 'other',
              uid: _attchsArr[i].uid
            }
            let suffix = _obj.name.substring(_obj.name.lastIndexOf('.') + 1)
            suffix = suffix.toLowerCase()
            if (imgTypes.indexOf(suffix) !== -1) {
              _obj.type = 'img'
            }
            _list.push(_obj)
          }
        }
        return _list
      },
      // 格式化需要传的客户信息表单
      parseForm () {
        let form = {}
        let phone, weixin, email
        phone = deepClone(this.phone.filter(obj => !!obj.tel))
        weixin = deepClone(this.weixin.filter(obj => !!obj.num))
        email = deepClone(this.email.filter(obj => !!obj.email))
        form = deepClone(this.form)
        let custTmpls = this.$getCache('custTmpls')
        form.dbType = custTmpls[0]._id
        // 编辑客户时， 如果号码是被隐藏的且没进行修改的话，取隐藏之前的值 tempTel
        // 反之去编辑之后的值， 添加的没被隐藏可直接存储
        phone = deepClone(phone.map((val) => {
          if (val.tempTel && val.tel.indexOf('*') > -1) {
            val.tel = val.tempTel
          }
          delete val.tempTel
          val.tel = phoneFilterChats(val.tel)
          return val
        }))
        form.phone = phone
        form.email = email
        form.weixin = weixin
        form.type = this.currentBusinessObj.type
        if (form.owner === this.$store.state.session.sessionId) {
          form.tabType = this.currentBusinessObj.tabType
        } else {
          if (form.type === 'customer') {
            form.tabType = 'customer_all'
          } else {
            form.tabType = this.currentBusinessObj.tabType
          }
        }
        form.callId = this.currentBusinessObj.callId
        form.dealSrc = this.currentBusinessObj.dealSrc

        if (this.editCustType === 'update') {
          for (let key in this.noUpdate) {
            if (this.noUpdate[key]) {
              if (this.dateIdArr.indexOf(key) !== -1) {
                form[key] = new Date(this.custInfo[key])
              } else {
                form[key] = this.custInfo[key]
              }
            }
          }
        }
        // 提交到后台数据 字段不能提交null
        // 这样移动端显示的时候会直接以null的形式显示 转化为‘’空字符串显示
        for (let key in form) {
          if (form[key] === null) {
            form[key] = ''
          }
          // 将生日时间格式化
          if (key === 'birth' && form[key]) {
            form[key] = this.getFormatDateTime(form[key])
          }
        }
        return form
      },
      parseDate (form) {
        for (let i = 0; i < this.optionsCustomFields.length; i++) {
          let field = this.optionsCustomFields[i]
          if (field.inputType === 'date' && form[field.name] instanceof Date) {
            let date = form[field.name]
            let year = date.getFullYear()
            let month = date.getMonth()
            month = month + 1 > 9 ? month + 1 : '0' + (month + 1)
            let day = date.getDate()
            day = day > 9 ? day : '0' + day
            form[field.name] = `${year}-${month}-${day}`
          } else if (field.inputType === 'datetime' && form[field.name] instanceof Date) {
            let date = form[field.name]
            let year = date.getFullYear()
            let month = date.getMonth()
            month = month + 1 > 9 ? month + 1 : '0' + (month + 1)
            let day = date.getDate()
            day = day > 9 ? day : '0' + day
            let hour = date.getHours()
            let minites = date.getMinutes()
            let second = date.getSeconds()
            hour = hour > 9 ? hour : '0' + hour
            minites = minites > 9 ? minites : '0' + minites
            second = second > 9 ? second : '0' + second
            form[field.name] = `${year}-${month}-${day} ${hour}:${minites}:${second}`
          }
        }
        return form
      },
      /**
       * [submit description]
       * @param  {[type]} vutFlag [如果为true, 则不需要提交请求]
       * @return {[type]}         [description]
       */
      submit (ev, vutFlag) {
        console.log(this.form)
        console.log(this.$refs.cascader)
        if (this.$refs.cascader && this.$refs.cascader.length !== 0) {
          let _arr = this.$refs.cascader
          for (let i = 0; i < _arr.length; i++) {
            console.log(_arr[i])
            console.log(_arr[i].formId)
            if (_arr[i].formId && Array.isArray(this.form[_arr[i].formId])) {
              _arr[i].handelChange(this.form[_arr[i].formId])
            }
          }
        }
        // 解决select第一次没有change的情况
        this.$refs.custStatus.getCustStatus()
        if (!this.form.status) {
          this.form.status = 'status'
        }
        let form = this.parseForm()
        this.form = deepClone(form)
        this.$refs.areaLink.emitValue()
        for (let i = 0; i < this.dateIdArr.length; i++) {
          if (this.form[this.dateIdArr[i]]) {
            this.form[this.dateIdArr[i]] = new Date(this.form[this.dateIdArr[i]])
          }
        }
        if (vutFlag) {
          return false
        }
        this.$nextTick(() => {
          this.$refs.form.validate((valid) => {
            if (valid) {
              form = this.parseDate(form)
              form.attachs = this.handleAttachs()
              // if (this.editCustType === 'add') {
              //   if (this.currentBusinessObj.type === 'call') {
              //     if (this.currentBusinessObj.tabType !== 'cdr_call') {
              //       let callObj = this.$store.state.call.current[this.currentBusinessObj.tabType]
              //       if (callObj) {
              //         let callInfo = callObj.callInfo
              //         if (callInfo && callInfo.CONNECT_TYPE) {
              //           if (callInfo.CONNECT_TYPE === 'normal' || callInfo.CONNECT_TYPE === 'transfer') {
              //             form.callTel = callInfo.CALL_NO
              //           } else {
              //             form.callTel = callInfo.CALLED_NO
              //           }
              //         }
              //       }
              //       form.dealSrc = 'relocationCall'
              //       form.actionType = 'self'
              //     }
              //     this.$store.dispatch('callLocationCustomer2Add', form).then((res) => {
              //       if (res && res.code === '1002' || res && res.code === '1001') {
              //         return false
              //       } else {
              //         this.$emit('editCust', 'call')
              //       }
              //       // this.$emit('editCust', form)
              //     })
              //     this.$emit('editCust', form)
              //   } else {
              //     this.$emit('editCust', form)
              //   }
              // } else {
              //   this.$emit('editCust', form)
              // }
              if (form.birth) {
                form.birth = form.birth.split(" ")[0]
              }
              this.$emit('editCust', form)
            } else {
              this.$message({
                type: 'error',
                message: this.$t('public.pleaseEnterRequireItem')
              })
              formRollToFirstError(this.$refs.form.$el) // 表单校验有问题时，滚动到第一个el-error的位置
              return false
            }
          })
        })
      },
      callBackAddCust () {
        this.$emit('callBackAddCust', true)
      },
      initFileMap () {
        if (!this.fileMap) {
          this.fileMap = {}
        }
      },
      updateFileMap (fileId, fileKey) {
        this.initFileMap()
        this.fileMap[fileId] = fileKey
      },
      clearFileMap () {
        this.fileMap = {}
      },
      beforeRemove (file, fileList) {
        // 当文件为空时 直接返回
        if (!file) return
        if (file.size > 10 * 1024 * 1024) {
          return true
        }
        let limitType = UPLOAD_LIMITED_TYPE
        let type = file.name.split('.').pop()
        if (limitType.includes(type)) {
          return true
        }
        if (!checkform(file.name, 'specialCharacter')) {
          return true
        }
        return this.$confirm(this.$t('customer.deleteCustomerAttachMessage'), this.$t('customer.deleteCustomerAttach'), {
          confirmButtonText: this.$t('public.confirm'),
          cancelButtonText: this.$t('public.cancel'),
          cancelButtonClass: 'primary_btn',
          confirmButtonClass: 'primary_btn',
          type: 'warning'
        })
      },
      handlePreview (file) {
        let url = common.getUrl(file, { noQuery: true })
        this.$store.commit(globalTypes.SET_FILEDOWNLOAD, { path: `${url}?attname=${file.name}`, isSession: false })
      },
      // 文件上传成功
      handleSuccess (response, originFile) {
        this.files = {}
        const file = this.isUseQiniu ? originFile : response.file
        let fileUrl = this.isUseQiniu ? response.key : response.fileKey
        this.initFileMap()
        this.updateFileMap(file.uid, fileUrl)
        let trueName = this.isUseQiniu ? file.name : fileUrl
        let uploadFile = { id: file.fullName || file.name, name: file.name, type: 'other', isNew: 1 }
        let imgTypes = ['jpg', 'jpeg', 'gif', 'png', 'bmp']
        let suffix = trueName.substring(trueName.lastIndexOf('.') + 1)
        suffix = suffix.toLowerCase()
        if (imgTypes.indexOf(suffix) !== -1) {
          uploadFile.type = 'img'
        }
        if (!this.attaches) {
          this.attaches = []
        }
        this.attaches.push(uploadFile)
      },
      // 在上传文件之前
      beforeUpload (file) {
        if (file.size > 50 * 1024 * 1024) {
          this.$message.error(this.$t('customer.attachSizeOverLimit'))
          // this.attachs = deepClone(this.attachs)
          return false
        }
        let limitType = UPLOAD_LIMITED_TYPE
        let type = file.name.split('.').pop()
        if (limitType.includes(type)) {
          this.$message.error("该文件类型禁止上传")
          return false
        }
        if (!checkform(file.name, 'specialCharacter')) {
          this.$message.error(this.$t('public.uploadValid'))
          return false
        }
        let key = generateUploadResourceKey(this.$store, file.name)
        return this.$store.dispatch('getImTestQiniuToken', {key}).then(response => {
          if (response.uptoken) {
            this.uploadData.token = response.uptoken
          }
          this.uploadData.key = key
        })
      },
      cosBeforeUpload(file) {
        if (file.size > 50 * 1024 * 1024) {
          this.$message.error(this.$t('customer.attachSizeOverLimit'))
          return false
        }
        this.cosKey = generateUploadResourceKey(this.$store, file.name)
        file.key = this.cosKey
        file.fullName = common.getUrl(file, {noQuery: true, idKey: 'key', domainKey: 'cos7moorCommonDomain'})
      },
      // 处理级联的change事件
      handleCascader (val) {
//        console.log(val)
//        isLeaf1 = val.isLeaf
        isLeafObj[val.id] = val.isLeaf
        this.$set(this.form, val.id, val.val)
      },
      // 处理省市县的change事件
      handleAreaLinkageChange (selectObj) {
        for (let key in selectObj) {
          this.form[key] = selectObj[key] ? selectObj[key] : ''
        }
      },
      // 处理客户状态的change
      handleStatusChange (value) {
        this.form.status = value || 'status0'
      },
      // 处理数据来源的change
      handleSourceChange (value) {
        this.form.custsource1 = value
      },
      // 处理无归属
      handleOwnerChange (obj) {
        Object.assign(this.form, obj)
      },
      // 微信 电话 邮件添加一行
      addLink (key) {
        key === 'phone' ? this[key]
        .push({
          memo: '',
          tel: '',
          isCheck: false
        }) : this[key]
        .push({
          memo: '',
          key: ''
        })
      },
      // 微信 电话 邮件删除一行
      delLink (key, index) {
        this[key].splice(index, 1)
      },
      // 校验省市区
      validateP (rule, value, callback) {
        if (!value) {
          callback(new Error(rule.message))
        } else if (value.length === 0) {
          callback(new Error(rule.message))
        } else {
          if (rule.flag === 'c') {
            this.$nextTick(function () {
              if (this.form.city === '') {
                callback(new Error(rule.message))
              } else {
                callback()
              }
            })
          } else if (rule.flag === 'd') {
            this.$nextTick(function () {
              var provinceInfo = this.provinceCache.find(d => d.key === this.form.province)
              var citysOptions = provinceInfo && provinceInfo.options || []

              var cityInfo = citysOptions.find(d => d.key === this.form.city)
              var districtsOptions = cityInfo && cityInfo.options || []

              if (this.form.city === '') {
                callback(new Error(rule.message))
              } else if (this.form.district === '' && districtsOptions.length) {
                callback(new Error(rule.message))
              } else {
                callback()
              }
            })
          } else {
            callback()
          }
        }
      },
      resetForm () {
        this.phone = [{ memo: '', tel: '' }]
        this.email = [{ memo: '', email: '' }]
        this.weixin = [{ memo: '', num: '' }]
      },
      clearValidate () {
        this.$nextTick(function () {
          this.$refs['form'].clearValidate()
        })
      },
      fetchData (resetForm1) {
        isLeafObj = {}
        // 清空文件上传的列表
        if (this.$refs.upload) {
          this.$refs.upload.clearFiles()
          this.clearFileMap()
        }
        this.attachs = [] // 初始化清空上传的附件
        this.noUpdate = { phone: false, name: false, title: false, province: false, address: false, note: false, web: false } // 重置是否禁用表单的
        this.form = { _id: null, dbType: null, name: null, status: 'status0', title: null, province: null, city: null, district: null, address: null, note: null, web: null, custsource1: null, thirdPartyRelationId: null, categoryId: null, owner: null, email: [], weixin: [], phone: [], attachs: [] }
        Promise.all([
          this.$store.dispatch('getCache', { type: 'custCategorys' }),
          this.$store.dispatch('getCache', { type: 'custTmpls' }),
          this.$store.dispatch('getCache', { type: 'agents' }),
          this.$store.dispatch('getCache', { type: 'getOldDic' }),
          this.$store.dispatch('getCache', { type: 'options', id: 'd7b9c68a-b50f-21d1-d5fd-41ea93f5f49c' })
        ]).then(([custCategorysCache, custTmpls, agents, oldDic, provinceCache]) => {
          this.hasFetchData = true
          let custTmpl = custTmpls[0]
          this.oldDic = oldDic || []
          // 客户类型 个人：personal 企业：business 如果是个人会新增sex age birth
          this.templateType = custTmpl.template_type
          if (this.templateType === 'personal') {
            this.$set(this.form, 'sex', '0')
            this.$set(this.form, 'age', null)
            this.$set(this.form, 'birth', null)
          } else {
            this.$set(this.form, 'custsource1', null)
            this.$set(this.form, 'web', null)
          }
          let customForm = Object.assign({}, this.form)
          this.provinceCache = provinceCache.options
          // 固定的显示字段
          let stableFields = custTmpl.stable_fields
          stableFields.forEach(ele => {
            this.showItem[ele.name] = ele.value
            this.isShowItem[ele.name] = ele.isShow || false
            // 如果是手机 微信 邮件 新增一条备注
            if (ele.name === 'phone' || ele.name === 'weixin' || ele.name === 'email') {
              this.showItem[ele.name + 'Memo'] = ele.value + this.$t('public.remark')
            }
            // 加入校验
            if (ele.required === 'required') {
              if (ele.name !== 'city' || ele.name !== 'district' || ele.name !== 'province') {
                this.rules[ele.name] = [{required: true, message: this.$t('public.pleaseInput') + ele.value, trigger: 'blur'}]
              }
              if (ele.name === 'phone') {
                this.rules[ele.name][0].validator = validatePhone
              }
              if (ele.name === 'weixin') {
                this.rules[ele.name][0].validator = validateWeixin
              }
              if (ele.name === 'email') {
                this.rules[ele.name][0].validator = validateEmail
              }
              // 通过flag去判定是省校验 还是省市校验 还是省市区校验
              if (ele.name === 'province') {
                this.rules[ele.name] = [{
                  validator: this.validateP,
                  trigger: 'change',
                  message: this.$t('customer.provinceRule'),
                  flag: 'p'
                }]
              }
              if (ele.name === 'city') {
                this.rules['province'][0].message = this.$t('customer.cityRule')
                this.rules['province'][0].flag = 'c'
              }
              if (ele.name === 'district') {
                this.rules['province'][0].message = this.$t('customer.districtRule')
                this.rules['province'][0].flag = 'd'
              }
            }
            // (!this.custInfo || this.custInfo[customField._id]) 把该语句修改为 this.custInfo[customField._id]
            if (notUpdateCustomerField(this.$store.state.session.user) && this.editCustType === 'update' && ele.noupdate === true && ((ele.name === 'phone' && this.custInfo[ele.name][0] && this.custInfo[ele.name][0].tel) || (ele.name !== 'phone' && this.custInfo[ele.name]))) {
              // 当为数组时 判断若为空则可继续填选
              this.$set(this.noUpdate, ele.name, true)
              if (this.custInfo[ele.name] && this.custInfo[ele.name].length === 0) {
                this.$set(this.noUpdate, ele.name, false)
              }
            }
//            if (notUpdateCustomerField(this.$store.state.session.user) && )
          })
          let dateIdArr = []
          // 自定义字段
          // 去除排序功能 20180118
          // let sortedCustomFields = sortCustomFields(custTmpl.custom_fields)
          let optionsCustomFields = []
          custTmpl.custom_fields.forEach(customField => {
            let option = { label: customField.name, name: customField._id, status: customField.status || 'run' }
            // 处理自定义字段格式
            if (customField.type === 'single') {
              option.inputType = 'input'
            } else if (customField.type === 'multi') {
              option.inputType = 'textarea'
            } else if (customField.type === 'number') {
              option.inputType = 'input'
              option.validateType = 'Number'
            } else if (customField.type === 'dropdown') {
              if (customField.dic) {
                option.inputType = 'cascade'
                option.data = customField.dic
              } else {
                option.inputType = 'select'
                option.data = [{ label: this.$t('public.pleasePick'), value: '' }]
                for (let key in customField.choices) {
                  option.data.push({ label: customField.choices[key] || ' ', value: key })
                }
              }
            } else if (customField.type === 'checkbox' || customField.type === 'radio') {
              option.inputType = customField.type
              option.data = []
              for (let key in customField.choices) {
                option.data.push({ label: customField.choices[key], value: key })
              }
            } else {
              option.inputType = customField.type
            }
            optionsCustomFields.push(option)
            if (customField.type === 'checkbox') {
              customForm[customField._id] = []
            } else {
              customForm[customField._id] = ''
            }

            // 添加校验
            if (customField.required === 'required') {
              let rule = [{ required: true, message: this.$t('public.pleaseInput') + customField.name, trigger: 'blur' }]
              if (customField.type === 'checkbox') {
                rule[0].type = 'array'
                rule[0].trigger = 'change'
              }
              if (customField.type === 'date') {
                rule[0].type = 'date'
                rule[0].trigger = 'change'
                dateIdArr.push(customField._id)
              }
              if (customField.type === 'dropdown' || customField.type === 'radio') {
                if (customField.dic) {
                  console.log(this.rules)
                  rule = [{ required: true, trigger: 'array', name: customField.name, validator: validateCascader }]
                  if (customField.mustFill) {
                    rule[0].mustFill = customField.mustFill
                  }
                  if (this.rules && this.rules[customField._id] && Array.isArray(this.rules[customField._id]) && this.rules[customField._id].length !== 0) {
                    let _obj = this.rules[customField._id][0]
                    if (_obj.cascadeLevel) {
                      rule[0].cascadeLevel = _obj.cascadeLevel
                    }
                  }
                }
                rule[0].trigger = 'change'
              }
              this.$set(this.rules, customField._id, rule)
            }
            if (customField.type === 'number') {
              let numberRule = { validator: validateNumber, message: customField.name + this.$t('customer.shouldBeNumber'), tigger: 'blur' }
              if (customField.required === 'required') {
                numberRule.validator = validateNumberReq
              }
              if (this.rules[customField._id]) {
                this.rules[customField._id].push(numberRule)
              } else {
                this.$set(this.rules, customField._id, [numberRule])
              }
            }
            // (!this.custInfo || this.custInfo[customField._id]) 把该语句修改为 this.custInfo[customField._id] 判断是否可以编辑
            if (notUpdateCustomerField(this.$store.state.session.user) && this.editCustType === 'update' && customField.noupdate === true && this.custInfo[customField._id]) {
              this.$set(this.noUpdate, customField._id, true)
              // 当为数组时 判断若为空则可继续填选
              if (Array.isArray(this.custInfo[customField._id]) && this.custInfo[customField._id].length === 0) {
                this.$set(this.noUpdate, customField._id, false)
              }
            }
            if (!notUpdateCustomerField(this.$store.state.session.user) && this.noUpdate[customField._id] && Array.isArray(this.custInfo[customField._id]) && this.custInfo[customField._id].length === 0) {
              this.$set(this.noUpdate, customField._id, false)
            }
          })
          // form初始值
          for (let key in customForm) {
            if (this.custInfo && this.custInfo[key]) {
              customForm[key] = deepClone(this.custInfo[key])
              if (key === 'phone' && this.custInfo[key].length !== 0) {
                if (this.isHideTel) {
                  let phone = deepClone(this.custInfo[key])
                  this[key] = phone.map(obj => {
                    obj.realTel = obj.tel
                    obj.tempTel = obj.tel
                    obj.tel = this.hideTel(obj.tel)
                    return obj
                  })
                } else {
                  this[key] = deepClone(this.custInfo[key])
                }
              }
              if (key === 'email' || key === 'weixin' || key === 'attachs') {
                if (this.custInfo[key].length !== 0) {
                  this[key] = deepClone(this.custInfo[key])
                }
              }
              if (dateIdArr.length > 0 && this.dateIdArr.indexOf(key) !== -1) {
                customForm[key] = new Date(this.custInfo[key])
              }
            }
          }
          this.form = customForm
          this.dateIdArr = dateIdArr
          this.optionsCustomFields = optionsCustomFields
          if (!this.form.status) {
            this.form.status = 'status'
          }
//          if (resetForm1) {
//            this.$nextTick(function () {
//              this.resetForm()
//              this.$refs['form'].resetFields()
//              console.log(this.form)
//              console.log(this.custInfo)
//            })
//          }
          // this.clearValidate()
        })
        if (!isHasFunc('func_not_allow_add_blacklist', this.$store.state.session.user)) {
          this.isToBlackList = true // 禁止加入黑名单权限
        }
      },
      resetAddCustomer1 () {
        let that = this
        that.hasFetchData = false
        that.resetForm()
        that.fetchData()
      }
    },
    watch: {
      custInfo () {
        console.log(this.form)
        console.log(this.custInfo)
        this.phone = [{ memo: '', tel: '' }]
        this.email = [{ memo: '', email: '' }]
        this.weixin = [{ memo: '', num: '' }]

        let customForm = Object.assign({}, this.form)

        for (let key in customForm) {
          if (this.custInfo && this.custInfo[key]) {
            customForm[key] = deepClone(this.custInfo[key])
            if (key === 'phone' && this.custInfo[key] && this.custInfo[key].length !== 0) {
              if (this.isHideTel) {
                let phone = deepClone(this.custInfo[key])
                this[key] = phone.map(obj => {
                  obj.realTel = obj.tel
                  obj.tempTel = obj.tel
                  obj.tel = this.hideTel(obj.tel)
                  return obj
                })
              } else {
                this[key] = deepClone(this.custInfo[key])
              }
            }
            if (key === 'email' || key === 'weixin') {
              if (this.custInfo[key] && this.custInfo[key].length !== 0) {
                this[key] = deepClone(this.custInfo[key])
              }
            }
            if (key === 'attachs') {
              this[key] = deepClone(this.custInfo[key]) || []
            }

            if (this.dateIdArr.length > 0 && this.dateIdArr.indexOf(key) !== -1) {
              customForm[key] = new Date(this.custInfo[key])
            }
          }
        }
        this.form = customForm
        if (!this.form.status) {
          this.form.status = 'status'
        }
      }
    },
    mounted () {
      console.log('add mounted')
      bus.$on('resetAddCustomer', this.resetAddCustomer1)
      if (this.isFull) {
        bus.$on('changeCusComponents', (msg) => {
          this.fetchData()
        })
      }
    },
    beforeDestroy () {
      this.clearFileMap()
      if (this.isFull) {
        bus.$off('changeCusComponents')
        bus.$off('changeCusSource')
        bus.$off('changeCusStatus')
        bus.$off('changeCusOwner')
        bus.$off('changeCascader')
      }
      bus.$off('resetAddCustomer', this.resetAddCustomer1)
    },
    beforeMount () {
      this.fetchData()
    }
  }
  function generateUploadResourceKey (store, name) {
    let date = getCurrentDate()
    let today = new Date()
    let time = today.getTime()
    let key = store.state.session.user.account + '/customer/' + date + '/' + time + '/' + String(Math.random() * Math.random()) + '/' + name
    return key
  }
  function validatePhone (rule, value, callback) {
    if (!value || value.length === 0 || !value[0].tel) {
      callback(new Error(rule.message))
    } else {
      callback()
    }
  }
  function validateWeixin (rule, value, callback) {
    if (!value || value.length === 0 || !value[0].num) {
      callback(new Error(rule.message))
    } else {
      callback()
    }
  }
  function validateEmail (rule, value, callback) {
    if (!value || value.length === 0 || !value[0].email) {
      callback(new Error(rule.message))
    } else {
      callback()
    }
  }
  function validateNumberReq (rule, value, callback) {
    if (value && /^[\d]+\.?\d*$/.test(value)) {
      callback()
    } else {
      callback(new Error(rule.message))
    }
  }
  function validateNumber (rule, value, callback) {
    if (!value || /^[\d]+\.?\d*$/.test(value)) {
      callback()
    } else {
      callback(new Error(rule.message))
    }
  }
  function validateCascader (rule, value, callback) {
    console.log(value)
    let _level = rule.cascadeLevel
    if (value.length !== 0) {
      if (rule.mustFill) {
        if (rule.mustFill !== 'all') {
          _level = rule.mustFill
        }
        if (value.length >= _level) {
          callback()
        } else {
          console.log(isLeafObj)
          if (isLeafObj[rule.field]) {
            callback()
          } else {
            callback(new Error('请必须填写' + _level + '级'))
          }
        }
      } else {
        callback()
      }
    } else {
      callback(new Error('请填写' + rule.name))
    }
  }
</script>
<style lang="stylus">
  .chat_info_todo
    .add
      height auto!important
  .c-add
    .add
      padding-top 15px
</style>
<style lang="stylus" scoped>
  @import "../../../assets/common.styl"
  .phone-tip
    line-height: 14px;
    font-size: 12px;
    color: #ff6b6b;
  .height-68
    height 80px
  .el-select
  .el-date-editor
    width 100%
  .el-form-item
    margin-bottom 10px
  .add
    overflow-x hidden
    /*padding-top 15px*/
    height calc(100% - 60px)
    box-sizing border-box
    .el-checkbox-group
      .el-checkbox
        margin-right 10px
    .is-merge
      padding  0 10px 0 0
  .el-form
    padding 0 50px
    margin-bottom 30px
  .edit_customer_info
    .el-form
      padding 0
      margin-bottom 45px
  .push
    font-size 18px
    color $c-main
    display inline-block
    font-weight 700
    margin-top 27px
    cursor pointer
  .del
    color red
    margin-top 8px
  .el-form .primary_btn
    margin-left 20px
    &:last-child
      margin-right 20px
  .call-screen-add,.show-callback-add
    max-height 400px
  .el-checkbox-group
  .el-radio-group
    white-space normal
    .el-checkbox
      margin -10px 0 0 0
      height 28px
  .form__footer
    position absolute
    left 0
    bottom 0
    width 100%
    border-radius 4px
    margin 0
    /*padding 4px 0*/
    background $cf-white
    z-index 6
    border-top 1px solid #dfe6ec
    text-align right
    border-top-left-radius 0
    border-top-right-radius 0
  .el-dialog
    .el-form
      margin-bottom 40px
  .add-item
    .el-col
      margin-bottom 12px
    .el-col-24
      .el-form-item
        margin-bottom 0
  .el-col.el-col-24.full-add
  .el-col.el-col-24.full-del
    display inline-block
    position absolute
    top -28px
    left 90%
  .el-col.el-col-24.full-del
    margin-top 16px
.dropdownStyle
  li
    text-align center
    line-height 28px
    cursor pointer
</style>